<?php

use App\Http\Controllers\Invoice\Merchant\IndexController as MerchantIndexController;
use App\Http\Controllers\Invoice\Merchant\InvoiceController;
use App\Http\Controllers\Invoice\Merchant\InvoiceHeaderManageController;
use App\Http\Controllers\Invoice\Web\IndexController as WebIndexController;
use App\Http\Middleware\OpenShop\FeishuWebAuth;
use App\Http\Middleware\OpenShop\MerchantAppAuth;
use App\Http\Middleware\OpenShop\UserPermissionAuth;
use Illuminate\Support\Facades\Route;

/**
 *
 * 开票路由
 */

Route::get('test', function () {
    return '开票';
});


// 商家app
Route::prefix('merchant')
     ->middleware(MerchantAppAuth::class)
     ->group(function () {

         // 申请开票
         Route::post('applyInvoice', [InvoiceController::class, "applyInvoice"])
              ->middleware('customerThrottle:1,2');

         // 申请换开
         Route::post('reApplyInvoice', [InvoiceController::class, "reApplyInvoice"])
              ->middleware('customerThrottle:1,2');

         // 开票列表
         Route::get('list', [InvoiceController::class, "list"]);

         // 开票详情
         Route::get('invoiceInfo/{id}', [InvoiceController::class, "info"])->where('id', '[0-9]+');

         // 转发开票信息(邮件)
         Route::post('invoiceTransmitEmail/{id}', [InvoiceController::class, 'transmitEmail'])->where('id', '[0-9]+');

         // 抬头管理
         Route::prefix('invoiceHeader')->group(function () {

             //获取门店的默认抬头
             Route::get('getDefaultInfo', [InvoiceHeaderManageController::class, 'getDefaultInfo']);

             // 抬头编辑
             Route::post('update/{id}', [InvoiceHeaderManageController::class, 'update'])->where('id', '[0-9]+');
         });



         // 订货开票
         Route::prefix('kfos')->group(function () {

             // 可开票订单列表
             Route::get('orderList', [MerchantIndexController::class, 'orderList']);
         });
     });
// web端后台路由
Route::prefix('web')
     ->middleware([
         FeishuWebAuth::class,
         UserPermissionAuth::class . ':invoice'
     ])->group(function () {

        //红冲
        Route::post('redInvoice', [\App\Http\Controllers\Invoice\Web\InvoiceController::class, "redInvoice"]);

        // 查看开票记录列表
        Route::get('/list', [WebIndexController::class, 'indexList']);
        // 查看开票记录详情
        Route::get('/info/{id}', [WebIndexController::class, 'info'])->where('id', '[0-9]+');
    });
